package Bot
// GoBot配置
import (
    "fmt"
    "io/ioutil"
    "time"
    "gopkg.in/yaml.v3"
)

type Config struct {
    GoBoxPath    string `yaml:"Go_Box_path"`
    FFMPEG_PATH  string `yaml:"FFMPEG_PATH"`
    BotID        int    `yaml:"Bot_id"`
    YunZaiPath   string `yaml:"YunZaiPath"`
    AlemonPath   string `yaml:"AlemonPath"`
    NodePath     string `yaml:"nodePath"`
    YunZaiBotPath string `yaml:"YunZaiBotPath"`
}

//读取配置文件
func ReadConfig() *Config {
    var config Config
    data, err := ioutil.ReadFile("config.yaml")
    if err != nil {
        fmt.Println(Red, "读取配置文件失败", err, Reset)
        time.Sleep(2 * time.Second)
    }
    err = yaml.Unmarshal(data, &config)
    if err != nil {
        fmt.Println(Red, "解析配置文件失败", err, Reset)
        time.Sleep(2 * time.Second)
    }
    return &config
}
// 写入配置文件
func WriteConfig(config *Config) {
    data, err := yaml.Marshal(config)
    if err != nil {
        fmt.Println(Red, "生成配置文件失败", err, Reset)
        time.Sleep(2 * time.Second)
    }
    err = ioutil.WriteFile("config.yaml", data, 0666)
    if err != nil {
        fmt.Println(Red, "保存配置文件失败", err, Reset)
        time.Sleep(2 * time.Second)
    }
}